<?php
	include ("koneksi.php");
$LoginUser = trim($_POST['username']);
$LoginPassword = trim($_POST['password']);
if($LoginUser == "" && $LoginPassword == "")
{
	echo"<SCRIPT> alert('Isikan kolom Username dan Password !!'); window.history.go(-1); </SCRIPT>\n";
	echo "<meta http-equiv=\"refresh\" content=\"0;URL=login.php\">";
	exit();
}
else{if ($LoginUser == "")
	{
	echo"<SCRIPT> alert('Isikan kolom Username !!'); window.history.go(-1); </SCRIPT>\n";
	echo "<meta http-equiv=\"refresh\" content=\"0;URL=login.php\">";
	exit();
	}
else{
	if($LoginPassword == ""){
	echo"<SCRIPT> alert('Isikan kolom Password !!'); window.history.go(-1); </SCRIPT>\n";
	echo "<meta http-equiv=\"refresh\" content=\"0;URL=login.php\">";
	exit();
	}
else
	{
	$pass_ok = md5($LoginPassword);
	$SQLCheck	= mysql_query("SELECT * FROM tb_login WHERE `username` = '".$LoginUser."' AND `password` = '".$pass_ok."'");
	if (mysql_num_rows($SQLCheck) == 0)
	{
	echo"<SCRIPT> alert('Username atau Password anda salah !!'); window.history.go(-1); </SCRIPT>\n";
	echo "<meta http-equiv=\"refresh\" content=\"0;URL=login.php\">";
	exit();
	}
	else
	{
	$AdminCheck		= mysql_fetch_object($SQLCheck);
	$AdminUsername	= $AdminCheck->username;
	session_register('AdminUsername');
	echo "<meta http-equiv=\"refresh\" content=\"0;URL=./index.php\">";
	exit();
	}
	}
	}
unset($SQLCheck);
}
